import React, { Component } from 'react';
import { bindActionCreators } from 'redux';
import { connect } from 'react-redux';

import XforcePagination from '@xforceplus/pagination';
import { getToSendList } from '../../module/action';
//------------------------------------------------
import TableContainer from '../TableContainer'
//------------------------------------------------

class ToSendCont extends Component {
  state = {
    pageSizeOptions: ['10', '20', '50', '100', '200'],// 指定每页可以显示多少条
  }

  // 翻页操作 page 跳转到的页数，pageSize 切换每页展示数量
  paginationChange = (page, pageSize) => {
    const { orderParam, logisticsRequestParam, record } = this.props
    this.props.getToSendList({
      LogisticsGoodsRequestParam: logisticsRequestParam,
      orderParam: orderParam,//排序方式
      pageParam: {
        pageIndex: page,//第几页
        pageRowCount: pageSize,//一页多少条
      }
    })
    record.changePage(page, pageSize)
    record.partRowKeys([], [])
  }
  // 当页全选操作 返回值 true or false
  toggleAllCheckedHandler = (boolean) => {
    const { record } = this.props;
    record.onCheckAllChange(boolean)
  };
  //当页部分选中操作
  chgSelectedRowKeys = (selectedRowKeys, selectedRows) => {
    const { record } = this.props;
    record.partRowKeys(selectedRowKeys, selectedRows)
  }
  render() {
    const { pageSizeOptions } = this.state
    const {
      toSendList,//待寄件列表
      countWait,//待寄件总数
      record,//全选
      // dataSource,//数据
    } = this.props;
    const total = parseInt(countWait.waitSend)
    return (
      <div className="logistics-container">
        <TableContainer
          chgSelectedRowKeys={this.chgSelectedRowKeys}
          selectedRowKeys={record.selectedRowKeys}
          dataSource={toSendList} />
        <XforcePagination
          total={total ? total : 0}
          currentPage={record.currentPage}
          checkedTotal={record.checkedTotal}
          defaultPageSize={record.defaultPageSize}
          isAllChecked={record.isAllChecked}
          indeterminate={record.indeterminate}
          pageSizeOptions={pageSizeOptions}
          onChange={this.toggleAllCheckedHandler}
          paginationChange={this.paginationChange}
        />
      </div>
    );
  }
};
function mapStateToProps(state) {
  const { countWait, toSendList, orderParam, logisticsRequestParam } = state.logistics;
  return {
    toSendList,//待寄送数据列表
    countWait,//待寄送总数
    orderParam,//排序参数
    logisticsRequestParam,//筛选器对象
  };
}

function mapDispatchToProps(dispatch) {
  return bindActionCreators({
    getToSendList
  }, dispatch);
}

export default connect(mapStateToProps, mapDispatchToProps)(ToSendCont);
